package com.tm.media.utils.utils;

import lombok.Data;

@Data
public class Result<T>{
    private int code;
    private String msg;
    private T data;

    public Result() {
    }

    public Result(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    //简化上面 ↑
    public Result(ResultCodeEnum resultCodeEnum, T data) {
        this.code = resultCodeEnum.getCode();
        this.msg = resultCodeEnum.getMsg();
        this.data = data;
    }

    //不要data
    public Result(ResultCodeEnum resultCodeEnum) {
        this.code = resultCodeEnum.getCode();
        this.msg = resultCodeEnum.getMsg();
    }

    public Result(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    //通过静态方法返回对象
    public static Result SUCCESS(Object data){
        return new Result(ResultCodeEnum.SUCCESS,data);
    }
    public static Result SUCCESS(int code,String msg){
        return new Result(code,msg);
    }
    //传enum
    public static Result SUCCESS(ResultCodeEnum resultCodeEnum){
        return new Result(resultCodeEnum);
    }

    //通过静态方法不传参返回对象
    public static Result SUCCESS(){
        return SUCCESS(null);
    }

    public static Result FAIL(){
        return new Result(ResultCodeEnum.FAIL);
    }

    public static Result FAIL(ResultCodeEnum resultCodeEnum){
        return new Result(resultCodeEnum);
    }

    public static Result FAIL(int code, String msg) {
        return new Result(code,msg);
    }
}
